<?php
########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 10/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);

//====================================================================================================================
//==> Include obrigatórias no script
//====================================================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//====================================================================================================================
//==> Inicializar Classes
//====================================================================================================================
$not  = new Persist;
$not2 = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;

//====================================================================================================================
//==> Instanciar TemplatePower para juntar o PHP + HTML
//====================================================================================================================
$tpl  = new TemplatePower('../../html/vendas/popup_pagamento_pedido.html');
$tpl->prepare();

//====================================================================================================================
//==> Recebe variaveis de pesquisa
//====================================================================================================================

$evento    = @$_GET['evento'];
$id        = @$_GET['id'];
$idcliente = @$_GET['idcliente'];

//====================================================================================================================
//==> Executa case conforme evento
//====================================================================================================================


if(isset($evento)){
	switch($evento){

		case 'novo': {

			//captura data e hora atual
			$dt      = $data->getDataHoje('-').' '.$data->getHora();
			$npedido = $sql->tratar($id,30);

			$not->sql = "Select id from titulos where id_pedido = '$npedido'";
			if($not->ler() > 0){
			   echo 'Ja ha um titulo para este pedido';
			   exit;
			}

			$not->sql = "Select valor from pedidos where id = '$npedido'";
			if($not->ler() > 0){
			   $not->ini();
		       $tpl->assign('valor',number_format($not->valor,2,',','.'));
		       $tpl->assign('entrada',number_format($not->valor,2,',','.'));
			   $valor = $not->valor;
			}
			
			$not->sql = "Insert into titulos (tipo, id_cliente, id_pedido, valor, data_hora, uid, ativo)
						 values ('1', '$idcliente', '$npedido', '$valor', '$dt', '$ID_USUARIO', '0')";
			$not->ins();
			
			$not->sql = "SELECT MAX(id) AS id FROM titulos";
			$not->ler();
			$not->ini();
			
		    $tpl->assign('titulo', $not->id);
		    $tpl->assign('pedido', $npedido);
		    $tpl->assign('gera_parcelas', '<input type="button" value="Gerar Parcelamento" onClick="gera_parcelas();">');
			

		break;
		}
		
		//Ativa titulo e parcelas se confirmado================================================================================
		case 'grava_titulo': {
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);

			$not->sql = "Update titulos set ativo = '1' where id = '$titulo'";
			$not->alt();
			
			$not->sql = "Update parcelas set ativo = '1' where id_titulo = '$titulo'";
			$not->alt();

			print 'T&iacute;tulo gerado com sucesso!';
			print '<input type="button" value="Fechar" onClick="window.close();">';
			exit;


		break;
		}

		//pagamento a vista em dinheiro=======================================================================================
		case 'avista': {
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');
				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '1', '$valor' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			print '<script language="javascript" type="text/javascript" src="../../javascript/vendas/popup_pagamento_pedido.js"></script>';
			print 'Confirma para gerar o T&iacute;tulo!<br><br>';
			print '<input type="button" value="Confirmar gera&ccedil;&atilde;o do t&iacute;tulo" onClick="grava_titulos('.$titulo.');">';
			exit;


		break;
		}
		
		
		
		
		//entrada em dinheiro + cheque========================================================================================
		case 'dinheiro_cheque': {
			
			//variaveis referente a entreda
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			
			if($fpg == 1){
			   $formae = 'dinheiro';
			}else{
			   $formae = 'deposito';
			}
			
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));
			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));
			
			//variaveis referente as parcelas
		  	$banco      = @$sql->tratar($_GET['banco'],3);
		  	$ag         = @$sql->tratar($_GET['ag'],30);
			$cc         = @$sql->tratar($_GET['cc'],30);
			$nr         = @$sql->tratar($_GET['nr'],30);
			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');
				
			//Grava entrada
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();

			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
					//grava o cheque
					$not->sql = "Insert into cheques (id_titulo,  dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
								 values('$titulo', '$dt_ck' , '$banco', '$ag', '$cc', '$nr', '$vl_parcela', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//localiza ultimo cheque inserido
					$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
					$not->ler();
					$not->ini();
					$idcheque = $not->id_cheque;
		
					//grava parcela entrada				
					$not->sql = "Insert into parcelas (id_titulo, id_cheque, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$idcheque', '$i', '$soma_nrpar', '$vl_parcela' , '$dt_ck', '2', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//soma nr do proximo cheque
					$nr++;
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					<script language="javascript" type="text/javascript" src="../../javascript/vendas/popup_pagamento_pedido.js"></script>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em dinheiro + cheques</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$formae.' 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							cheque 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					<input type="button" value="Confirmar gera&ccedil;&atilde;o do t&iacute;tulo" onClick="grava_titulos('.$titulo.');">
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
								
								
								
								
								
			';
			exit;


		break;
		}



		//entrada em cartao + cheque========================================================================================
		case 'cartao_cheque': {

			//variaveis referente a entreda
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			
			if($fpg == 3){
				$formae = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpg == 4){
				$formae = 'Cart&atilde;o D&eacute;bito';	
			}
			
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

		  	$bancoe      = @$sql->tratar($_GET['bco'],3);
		  	$bandeirae   = @$sql->tratar($_GET['bandeira'],30);
		  	$ncartaoe    = @$sql->tratar($_GET['ncartao'],30);

			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));
			
			//variaveis referente as parcelas
		  	$banco      = @$sql->tratar($_GET['banco'],3);
		  	$ag         = @$sql->tratar($_GET['ag'],30);
			$cc         = @$sql->tratar($_GET['cc'],30);
			$nr         = @$sql->tratar($_GET['nr'],30);
			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');
				
			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$bandeirae', '$ncartaoe', '$bancoe', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			


			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
					//grava o cheque
					$not->sql = "Insert into cheques (id_titulo,  dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
								 values('$titulo', '$dt_ck' , '$banco', '$ag', '$cc', '$nr', '$vl_parcela', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//localiza ultimo cheque inserido
					$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
					$not->ler();
					$not->ini();
					$idcheque = $not->id_cheque;
		
					//grava parcela entrada				
					$not->sql = "Insert into parcelas (id_titulo, id_cheque, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$idcheque', '$i', '$soma_nrpar', '$vl_parcela' , '$dt_ck', '2', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//soma nr do proximo cheque
					$nr++;
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em cartao + cheques</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$formae.' 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							cheque 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
								
								
								
								
								
			';
			exit;


		break;
		}
		

		//entrada em cartao + cartao========================================================================================
		case 'cartao_cartao': {

			//variaveis referente a entrada
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			
			if($fpg == 3){
				$formae = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpg == 4){
				$formae = 'Cart&atilde;o D&eacute;bito';	
			}
			
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

		  	$bancoe      = @$sql->tratar($_GET['bco'],3);
		  	$bandeirae   = @$sql->tratar($_GET['bandeira'],30);
		  	$ncartaoe    = @$sql->tratar($_GET['ncartao'],30);

			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));
			
			//variaveis referente as parcelas
			$fpp        = @$sql->tratar($_GET['fpp'],3);

			if($fpp == 3){
				$formap = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpp == 4){
				$formap = 'Cart&atilde;o D&eacute;bito';	
			}

		  	$banco      = @$sql->tratar($_GET['bcop'],3);
		  	$bandeira   = @$sql->tratar($_GET['bandeirap'],3);
		  	$ncartao    = @$sql->tratar($_GET['ncartaop'],3);


			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');
				
			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$bandeirae', '$ncartaoe', '$bancoe', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			


			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
		
					//grava parcela			
					$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$i', '$soma_nrpar', '$bandeira', '$ncartao', '$banco', '$vl_parcela' , '$dt_ck', '$fpp', '$dt', '$ID_USUARIO')";
					$not->ins();
					
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em cartao + parcela em cartao</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$formae.' 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$formap.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
			';
			exit;


		break;
		}
		

		//entrada em dinheiro/depodito + cartao========================================================================================
		case 'dinheiro_cartao': {

			//variaveis referente a entrada
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			
			if($fpg == 1){
				$formae = 'dinheiro';	
			}else if($fpg == 6){
				$formae = 'Dep&oacute;sito';	
			}
			
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));


			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));
			
			//variaveis referente as parcelas
			$fpp        = @$sql->tratar($_GET['fpp'],3);

			if($fpp == 3){
				$formap = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpp == 4){
				$formap = 'Cart&atilde;o D&eacute;bito';	
			}

		  	$banco      = @$sql->tratar($_GET['bcop'],3);
		  	$bandeira   = @$sql->tratar($_GET['bandeirap'],3);
		  	$ncartao    = @$sql->tratar($_GET['ncartaop'],3);


			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');
				
			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			


			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
		
					//grava parcela			
					$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$i', '$soma_nrpar', '$bandeira', '$ncartao', '$banco', '$vl_parcela' , '$dt_ck', '$fpp', '$dt', '$ID_USUARIO')";
					$not->ins();
					
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em dinheiro + parcela em cartao</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$formae.' 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$formap.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
			';
			exit;


		break;
		}
		


		//entrada em cheque + cartao========================================================================================
		case 'cheque_cartao': {
			
			//variaveis referente a entreda
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));

		  	$bancoe       = @$sql->tratar($_GET['bco'],3);
		  	$agenciae     = @$sql->tratar($_GET['ag'],30);
		  	$contae       = @$sql->tratar($_GET['cc'],30);
		  	$numeroe      = @$sql->tratar($_GET['nr'],30);
		  	$dt_cke       = @$sql->tratar($_GET['dtck'],10);
			$dt_cke       = $data->getDataFormatada($dt_cke);


			//variaveis referente as parcelas
			$fpp        = @$sql->tratar($_GET['fpp'],3);

			if($fpp == 3){
				$formap = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpp == 4){
				$formap = 'Cart&atilde;o D&eacute;bito';	
			}

		  	$banco      = @$sql->tratar($_GET['bcop'],3);
		  	$bandeira   = @$sql->tratar($_GET['bandeirap'],3);
		  	$ncartao    = @$sql->tratar($_GET['ncartaop'],3);


			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');

			
			//grava o cheque
			$not->sql = "Insert into cheques (id_titulo, dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
						 values('$titulo', '$dt_cke' , '$bancoe', '$agenciae', '$contae', '$numeroe', '$entrada', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			//localiza ultimo cheque inserido
			$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
			$not->ler();
			$not->ini();
			$idcheque = $not->id_cheque;

			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cheque, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$idcheque', '$entrada' , '$dt_cke', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();

			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
		
					//grava parcela			
					$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$i', '$soma_nrpar', '$bandeira', '$ncartao', '$banco', '$vl_parcela' , '$dt_ck', '$fpp', '$dt', '$ID_USUARIO')";
					$not->ins();
					
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em cheque + parcela em cartao</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					cheque 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dt_cke).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$formap.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
								
								
								
								
								
			';
			exit;


		break;
		}


		//entrada em dinheiro + cartao========================================================================================
		case 'dinheiro_cartao': {
			
			//variaveis referente a entreda
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			
			if($fpg == 1){
				$forma = 'dinheiro';	
			}else if($fpg == 6){
				$forma = 'dep&oacute;sito';	
			}
			
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));

			//variaveis referente as parcelas
			$fpp        = @$sql->tratar($_GET['fpp'],3);

			if($fpp == 3){
				$formap = 'Cart&atilde;o Cr&eacute;dito';	
			}else if($fpp == 4){
				$formap = 'Cart&atilde;o D&eacute;bito';	
			}

		  	$banco      = @$sql->tratar($_GET['bcop'],3);
		  	$bandeira   = @$sql->tratar($_GET['bandeirap'],3);
		  	$ncartao    = @$sql->tratar($_GET['ncartaop'],3);


			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');

			
			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();

			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
		
					//grava parcela			
					$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$i', '$soma_nrpar', '$bandeira', '$ncartao', '$banco', '$vl_parcela' , '$dt_ck', '$fpp', '$dt', '$ID_USUARIO')";
					$not->ins();
					
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em dinheiro + parcela em cartao</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$forma.' 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$formap.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
								
								
								
								
								
			';
			exit;


		break;
		}


		//entrada em cheque + cheque========================================================================================
		case 'cheque_cheque': {

			//variaveis referente a entreda
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

			$entrada     = @$sql->tratar($_GET['entrada'],20);
		  	$entrada     = str_replace(",",".",str_replace(".","",$entrada));

		  	$bancoe       = @$sql->tratar($_GET['bco'],3);
		  	$agenciae     = @$sql->tratar($_GET['ag'],30);
		  	$contae       = @$sql->tratar($_GET['cc'],30);
		  	$numeroe      = @$sql->tratar($_GET['nr'],30);
		  	$dt_cke       = @$sql->tratar($_GET['dtck'],10);
			$dt_cke       = $data->getDataFormatada($dt_cke);


			//variaveis referente as parcelas
		  	$banco      = @$sql->tratar($_GET['banco'],3);
		  	$ag         = @$sql->tratar($_GET['agencia'],30);
			$cc         = @$sql->tratar($_GET['conta'],30);
			$nr         = @$sql->tratar($_GET['numero'],30);
			$nrpar      = @$sql->tratar($_GET['nrpar'],30);
			$soma_nrpar = $nrpar + 1;

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');

			//grava o cheque
			$not->sql = "Insert into cheques (id_titulo, dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
						 values('$titulo', '$dt_cke' , '$bancoe', '$agenciae', '$contae', '$numeroe', '$entrada', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			//localiza ultimo cheque inserido
			$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
			$not->ler();
			$not->ini();
			$idcheque = $not->id_cheque;

			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cheque, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '$soma_nrpar', '$idcheque', '$entrada' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			//calcula valor da parcela
			$subtotal   = $valor - $entrada;
			$vl_parcela = $subtotal / $nrpar;
			
			//Gera parcelas
			$dt_ck = $dtv;
			for($i=2;$i<=$soma_nrpar;$i++){	
					
					//calcula data de vencimento do cheque
					$dt_ck = $data->getAcresData($dt_ck,2,1);
							
					//grava o cheque
					$not->sql = "Insert into cheques (id_titulo,  dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
								 values('$titulo', '$dt_ck' , '$banco', '$ag', '$cc', '$nr', '$vl_parcela', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//localiza ultimo cheque inserido
					$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
					$not->ler();
					$not->ini();
					$idcheque = $not->id_cheque;
		
					//grava parcela entrada				
					$not->sql = "Insert into parcelas (id_titulo, id_cheque, parcela, de, valor, dt_venc, form_pag, data_hora, uid)
								 values('$titulo', '$idcheque', '$i', '$soma_nrpar', '$vl_parcela' , '$dt_ck', '2', '$dt', '$ID_USUARIO')";
					$not->ins();
					
					//soma nr do proximo cheque
					$nr++;
			}

			
			print '
			
								
					<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
					<html xmlns="http://www.w3.org/1999/xhtml">
					<head>
					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
					<title>Recibo</title>
					</head>
					
					<body>
					
					<table cellpadding="0" cellspacing="0" width="100%">
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					<font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
					<b>RECIBO PEDIDO: Entrada em cheque + cheques</b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="20" colspan="4">
					&nbsp;
					</td>
					</tr>
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Nr T&iacute;tulo: </b> 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor Total: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$titulo.' 
					</font>
					</td>
					<td colspan="3">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($valor,2,',','.').'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Entrada R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Data: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.number_format($entrada,2,',','.').' 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					cheque 
					</font>
					</td>
					<td colspan="2">
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					'.$data->getDataFormatada($dtv).'
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					
					<tr>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Parcela R$: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Forma Pg: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Dt. Vencimento: </b> 
					</font>
					</td>
					<td>
					&nbsp;&nbsp;
					<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
					<b>Valor R$: </b> 
					</font>
					</td>
					</tr>
					
					<tr>
					<td height="8" colspan="4">
					</td>
					</tr>
					
					';
					
					
					$not->sql = "Select parcela, form_pag, dt_venc, valor from parcelas where id_titulo = '$titulo' and parcela > 1 order by parcela asc";
					if($not->ler()){
					   while($not->ini()){
					
							print '
							<tr>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$not->parcela.' 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							cheque 
							</font>
							</td>
							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.$data->getDataFormatada($not->dt_venc).' 
							</font>
							</td>

							<td>
							&nbsp;&nbsp;
							<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">
							'.number_format($not->valor,2,',','.').'
							</font>
							</td>
							</tr>
							
							<tr>
							<td height="8" colspan="4">
							
							</td>
							</tr>
							';
							
						   
					   }
					
					}
					print '
					<tr>
					<td colspan="4" height="30" align="left" valign="middle" bgcolor="#0066CC">
					&nbsp;&nbsp;
					</td>
					</tr>
					
					</table>
					
					</body>
					</html>
								
								
								
								
								
								
								
			';
			exit;


		break;
		}
		
		
		
		case 'avista_ck': {
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

		  	$banco       = @$sql->tratar($_GET['bco'],3);
		  	$agencia     = @$sql->tratar($_GET['ag'],30);
		  	$conta       = @$sql->tratar($_GET['cc'],30);
		  	$numero      = @$sql->tratar($_GET['nr'],30);
		  	$dt_ck       = @$sql->tratar($_GET['dtck'],10);
			$dt_ck       = $data->getDataFormatada($dt_ck);

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');

			//grava o cheque
			$not->sql = "Insert into cheques (id_titulo,  dt_ven, id_banco, agencia, conta, numero, valor, data_hora, uid)
						 values('$titulo', '$dt_ck' , '$banco', '$agencia', '$conta', '$numero', '$valor', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			//localiza ultimo cheque inserido
			$not->sql = "SELECT MAX(id) AS id_cheque FROM cheques where uid = '$ID_USUARIO'";
			$not->ler();
			$not->ini();
			$idcheque = $not->id_cheque;

			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cheque, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '1', '$idcheque', '$valor' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			print 'Pagamento a vista com cheque finalizado com sucesso!';
			exit;


		break;
		}

		case 'avista_cartao': {
		  	$titulo      = @$sql->tratar($_GET['titulo'],30);
		  	$fpg         = @$sql->tratar($_GET['fp'],2);
			$valor       = @$sql->tratar($_GET['valor'],20);
		  	$valor       = str_replace(",",".",str_replace(".","",$valor));

		  	$banco       = @$sql->tratar($_GET['bco'],3);
		  	$bandeira    = @$sql->tratar($_GET['bandeira'],30);
		  	$ncartao     = @$sql->tratar($_GET['ncartao'],30);

			//captura data e hora atual
			$dt  = $data->getDataHoje('-').' '.$data->getHora();
			$dtv = $data->getDataHoje('-');

			//grava parcela entrada				
			$not->sql = "Insert into parcelas (id_titulo, parcela, de, id_cartao, nr_cartao, id_banco, valor, dt_venc, form_pag, data_hora, uid)
						 values('$titulo', '1', '1', '$bandeira', '$ncartao', '$banco', '$valor' , '$dtv', '$fpg', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			print 'Pagamento a vista com cartao finalizado com sucesso!';
			exit;


		break;
		}

		

	}
}



//LOOP FORMAS DE PAGAMENTO ENTRADA==================================================================
$not2->sql = "select id, descricao from formas_pagamento where ativo = '1' order by id asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('FPENTRADA');
        $tpl->assign('id_form_ent',$not2->id);
        $tpl->assign('n_form_ent',$not2->descricao);
	}
}

//LOOP FORMAS DE PAGAMENTO PARCELAS=================================================================
$not2->sql = "select id, descricao from formas_pagamento where ativo = '1' order by id asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('FPPARCELA');
        $tpl->assign('id_form_par',$not2->id);
        $tpl->assign('n_form_par',$not2->descricao);
	}
}

//LOOP BANDEIRAS ===================================================================================
$not2->sql = "select id, nome, tipo from cartoes where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANDEIRAS');
		if($not2->tipo == 1){
		   $tipo = ' - d&eacute;bito';			
		}else{
		   $tipo = ' - cr&eacute;dito';			
		}
		
        $tpl->assign('id_bandeira',$not2->id);
        $tpl->assign('n_bandeira',$not2->nome.$tipo);
	}
}

//LOOP BANCOS======================================================================================
$not2->sql = "select id, nome, codigo from bancos where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANCOS1');
        $tpl->assign('id_banco1',$not2->id);
        $tpl->assign('n_banco1',$not2->nome);
	}
}

//LOOP BANCOS======================================================================================
$not2->sql = "select id, nome, codigo from bancos where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANCOS2');
        $tpl->assign('id_banco2',$not2->id);
        $tpl->assign('n_banco2',$not2->nome);
	}
}

//LOOP BANDEIRASP ===================================================================================
$not2->sql = "select id, nome, tipo from cartoes where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANDEIRASP');
		if($not2->tipo == 1){
		   $tipo = ' - d&eacute;bito';			
		}else{
		   $tipo = ' - cr&eacute;dito';			
		}
		
        $tpl->assign('id_bandeirap',$not2->id);
        $tpl->assign('n_bandeirap',$not2->nome.$tipo);
	}
}

//LOOP BANCOSP======================================================================================
$not2->sql = "select id, nome, codigo from bancos where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANCOS1P');
        $tpl->assign('id_banco1p',$not2->id);
        $tpl->assign('n_banco1p',$not2->nome);
	}
}

//LOOP BANCOSP======================================================================================
$not2->sql = "select id, nome, codigo from bancos where ativo = '1' order by nome asc ";
if ($not2->ler() > 0){
	while($not2->ini()){
	    $tpl->newBlock('BANCOS2P');
        $tpl->assign('id_banco2p',$not2->id);
        $tpl->assign('n_banco2p',$not2->nome);
	}
}



//==================================================================================================
//==> Enviar página unificada PHP + HTML
//==================================================================================================
$tpl->showUnAssigned( false );  // para debug. na hora de publicar, setar para false
$tpl->printToScreen();
?>